<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
	xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout">
<head th:include="inc/home::header">
</head>
<link type="text/css" th:href="@{/css/content.css}" rel="stylesheet" />
<body>
	<!--返回-->
	<div class="back" onclick="loadPage('/documentation')">
		<img src="images/back.png" />
	</div>
	<div class="head-top">
		<div th:include="header :: header"></div>
	</div>
	<div class="header-title">
		<span>添加法规规范文档</span>
	</div>
	<div class="spare-a">
		<div class="save-bg">
			<a href="javascript:void(0)" class="spare-tj" onClick="Save()">保 存</a>
		</div>
		<div class="spare-add">
			<ul>
				<li>
					<div class="spare-addl">文件：</div>
					<div class="spare-addr">
						<form name="form" method="post" action="">
							<input type="text" name="uploadfile" id="uploadfile" class="spare-add-input" />
							<input type="button" name="submit" value="上 传"
								onClick="this.form.file.click();" class="uploadfile" /> <input
								type="file" name="file" id="file" style="display: none;"
								  onchange="fileChange(this);"/>
						</form>
					</div>
				</li>
			</ul>
		</div>
	</div>
</body>
<script th:inline="javascript">
	/*<![CDATA[*/
	
function fileChange(target){  
 $("#uploadfile").val(target.value);
//检测上传文件的类型 
var imgName = document.all.file.value;
     var ext,idx;   
    if (imgName == ''){  
        alert("请选择需要上传的文件!");  
        return; 
    } else {   
        idx = imgName.lastIndexOf(".");   
        if (idx != -1){   
            ext = imgName.substr(idx+1).toUpperCase();   
            ext = ext.toLowerCase( ); 
            if (ext != 'doc' && ext != 'docx' && ext != 'xlsx' && ext != 'xls'&& ext != 'pdf'){
      
                alert("只能上传.docx  .doc  .xlsx  .xls .pdf类型的文件!"); 
                return ;  
            }   
        } else {  
        	   alert("只能上传.docx  .doc  .xlsx  .xls .pdf类型的文件!"); 
            return ;
        }   
    }
    
   
    
    
    
    
}
   
/*     //检测上传文件的大小        
    var isIE = /msie/i.test(navigator.userAgent) && !window.opera;  
    var fileSize = 0;           
    if (isIE && !target.files){       
        var filePath = target.value;       
        var fileSystem = new ActiveXObject("Scripting.FileSystemObject");          
        var file = fileSystem.GetFile (filePath);       
        fileSize = file.Size;      
    } else {      
        fileSize = target.files[0].size;       
    }     

    var size = fileSize / 1024*1024;   

    if(size>(1024*1)){    

        alert("文件大小不能超过1KB");   
    }else{
    }   
    
    
    }    
      */
	           
	           
      var limitFileSize=function (file, limitSize) {
          var arr = ["KB", "MB", "GB"]
          var limit = limitSize.toUpperCase();
          var limitNum = 0;
          for (var i = 0; i < arr.length; i++) {
              var leval = limit.indexOf(arr[i]);
              if (leval > -1) {
                  limitNum = parseInt(limit.substr(0, leval)) * Math.pow(1024, (i + 1))
                  break
              }
          }
          if (file.size > limitNum) {
              return false
          }
          return true
      }      
	           
	function verifyNull(obj) {

		if (obj == null || obj.val() == "" || obj.val() == "请选择") {
			top.$
					.Zebra_Dialog(
							'<div class="prompt"><div class="warning-icon"></div><div class="success-title">输入的内容不能包含空</div></div>',
							{
								'title' : '提示',
								'buttons' : [ '确定' ]
							});
			return false;
		}
		return true;
	}
	function getData() {
		if (!verifyNull($("#file"))) {
			return false;
		}
		return true;
	}
	function Save() {
 		var validate = getData();
		if (!validate) {
			return false;
		} 

		
		$.ajaxFileUpload({
					url : '/FileUpload', //用于文件上传的服务器端请求地址
					type : 'post',
					secureuri : false, //是否需要安全协议，一般设置为false
					fileElementId:['file'], //文件上传域的ID 在这里设置要上传的多个input的ID
					dataType : 'json', //返回值类型 一般设置为json
					success : function(data, status) //服务器成功响应处理函数
					{

						if (data.success) {
							$.Zebra_Dialog(
											'<div class="prompt"><div class="success-icon"></div><div class="success-title">保存成功</div></div>',
											{
												'title' : '提示',
												'show_close_button' : false,
												'buttons' : [ {
													caption : '确定',
													callback : function() {
														loadPage("/documentation");

													}
												} ]
											});
						}else{
							$.Zebra_Dialog(
									'<div class="prompt"><div class="success-icon"></div><div class="success-title">文件超过10M</div></div>',
									{
										'title' : '提示',
										'show_close_button' : false,
										'buttons' : [ {
											caption : '确定'
									
										} ]
									});
						}
					},
					error : function(data, status, e)//服务器响应失败处理函数
					{
						$.Zebra_Dialog(
								'<div class="prompt"><div class="success-icon"></div><div class="success-title">保存失败</div></div>',
								{
									'title' : '提示',
									'show_close_button' : false,
									'buttons' : [ {
										caption : '确定'
									
									} ]
								});
					}
				});

	}

	/*]]>*/
</script>
</html>
